Repository navigation
feat: phones get a board framed for portrait and on-screen keys, for 0.5.2 - #83
Merged
Merged
Conversation
…0.5.2 fitCamera frames a portrait window for its shape: the camera looks down more steeply (70 degrees), the board fills the window's width and stands in the middle of the space below a HUD, and a large board no longer runs off the sides. Landscape and square windows keep 0.5.1's framing exactly (the golden image is unchanged); between an aspect of 0.8 and 1 the two blend. fitCamera, GridBoard.camera and GridBoard.scene take `top` and `bottom`, the fractions of the window kept clear of the board, and both views take them in pixels with setInsets(); picking and the web view's camera follow. TouchKeys (grid3d/touchkeys.py) lays out a bar of labelled buttons along the bottom of the screen, at least 44 CSS pixels each way, paging with More when the keys don't fit. A tap posts the KEYDOWN and KEYUP the keyboard would, so a game's own key handling does the work; the 2D view draws the bar with Graphik and the 3D view as screen panels and labels, from one layout and one hit test. below() sizes the band a 2D game adds under its board. The page template's Graphik3D.touch() and grid3d.web.touchScreen() say whether the page is on a touch screen (?touch=1 or ?touch=0 for testing). The version is 0.5.2; the README describes both. drafted by Claude on behalf of Daniel Stephenson Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LYNeuoCqxFpUXrFhxnTg89
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two things a phone needs are added to grid3d, and the version is bumped to 0.5.2.
A board framed for a phone held upright.
fitCameraused the desktop's framing at every aspect, so on a phone held upright the 3D board sat low and looked small (and a large board, such as Apex's 29 x 29, ran off both sides). A portrait window (aspect below 1) is now framed for its shape: the camera looks down more steeply (70 degrees rather than about 55), the board fills the window's width (2% margins) and stands in the middle of the space below a HUD. Landscape and square windows keep 0.5.1's framing exactly, so the golden image is unchanged; between an aspect of 0.8 and 1 the two framings blend, so a resize across square doesn't make the board jump.fitCamera,GridBoard.cameraandGridBoard.scenetaketopandbottom, the fractions of the window's height kept clear of the board (a HUD, a bar of touch keys), in any window shape. Both views take them in pixels withview.setInsets(top=..., bottom=...); picking,cellScreenPositionand the web view's camera (a new VIEW is sent at once) follow.On-screen keys for touch screens.
TouchKeys(grid3d/touchkeys.py) lays out a bar of labelled buttons along the bottom of the screen, each at least 44 CSS pixels each way, in rows of equal buttons (up to three rows on a portrait screen, one on a landscape one). When the keys don't all fit, the last button is More (Back on the last page), which pages through the rest, so the bar never grows over the board. A tap (keys.press(position, width, height, pygame, scale)) posts the sameKEYDOWNandKEYUPthe keyboard would (markedtouchKey=True), so a game's own key handlers do the work and the two views can't drift: parity by construction. The 2D view draws the bar with Graphik (keys.draw(graphik, ...)), the 3D view addskeys.overlay(...)(panels and labels) to its HUD, both from onelayout()and one hit test. Sizes are worked out in CSS pixels;scaleis a surface's CSS pixels per pixel, andkeys.below(width, height, pageWidth, pageHeight)gives the band a 2D game adds under its board and the canvas's scale once the browser fits it to the page.The page template's
Graphik3D.touch()andgrid3d.web.touchScreen()say whether the page is on a touch screen: a coarse pointer, or a touch already seen (a laptop's touch screen).?touch=1or?touch=0in the address overrides it for testing, andGRAPHIK_TOUCH=1does outside a browser.Measurements
The board's on-screen bounding box (frame included) as a share of a 390 x 844 phone screen in 3D, now and with 0.5.1's camera, read from what each game sent the page's relay (screenshots in
/root/scratch/shots/2026-11-20-touch-portrait/):A board can't grow past the phone's width, so the gain in a portrait window comes from standing the board taller (the steeper camera), using the full width with 2% margins and centring it in the room left by the HUD and the keys.
Landscape and desktop windows: unchanged (checked to 1e-3 against 0.5.1's camera in each game's end-to-end run).
Tests
test_grid3d_touch.py(new): the desktop formula is kept for every landscape and square window; the whole board stays on screen at 390x844, 844x390, 800x600, 1280x800, 900x700, 430x932 and 600x800 for seven board shapes; a portrait phone fills its width, centres the board and shows it bigger than 0.5.1 did; reserved space at the top and bottom is kept clear at every aspect; nearly square windows blend without a jump; a view's insets reach its camera, picking and the web view's VIEW; the keys' rows, sizes (44 px), paging with More and Back, key events (pygame's names), the 2D layout being the 3D layout scaled,below()on portrait and landscape phones, the 2D bar drawn with Graphik and the 3D bar as panels and labels with the same hit test;touchScreen()in a browser, with an older template and outside one.Each game's adoption PR runs the keys end to end in a browser at 390 x 844 with touch, in 3D and in 2D.
drafted by Claude on behalf of Daniel Stephenson
🤖 Generated with Claude Code